package com.zephyr.vchcenter.bpm.decision;

import org.apache.log4j.Logger;

import com.hiaward.bpm.context.ServiceContext;
import com.hiaward.bpm.exception.ParameterException;
import com.hiaward.bpm.exception.RuleException;
import com.hiaward.bpm.exception.ServiceException;
import com.hiaward.bpm.rule.Decision;
import com.zephyr.vchcenter.bean.Voucher;
import com.zephyr.vchcenter.dao.IBaseDao;
import com.zephyr.vchcenter.helper.SpringHelper;
import com.zephyr.vchcenter.service.impl.CreateProcessImpl;

public class NeedTallyDecisionHandler extends Decision {
	private final Logger log=Logger.getLogger(NeedTallyDecisionHandler.class);
	@Override
	public void exceptionHandle(ServiceContext arg0) {
	

	}

	@Override
	public String make(ServiceContext arg0) throws RuleException,
			ServiceException, ParameterException {
		 log.debug("进入NeedTallyDecisionHandler");
         String vchsid=(String)arg0.getInputParameterValue("vchsid");
         log.debug("主键："+vchsid);
         IBaseDao dao=(IBaseDao)SpringHelper.getBean("baseDao");
         Voucher voucher=(Voucher)dao.findById("Voucher", vchsid);
         String restally=voucher.getRestally();
         log.debug(restally);
         String amount=voucher.getAmount();
         String transition=null;
         if("1".equals(restally)){
        	 log.debug("退票");
        	 voucher.setTallytype("2");
        	 transition="to refuse";
         }else if("2".equals(restally)){
        	 voucher.setRestally(null);
        	 voucher.setChkstate("1");
        	 log.debug("转回审票");
        	 transition="to auditAfterTallyDecision"; 
         }
         else{ 
        	 log.debug("记账");
        	 voucher.setTallytype("1");
        	 transition="to tally";
         }
         dao.saveOrUpdate(voucher);
         arg0.setOutputParameterValue("vchsid", vchsid);
         log.debug("离开NeedTallyDecisionHandler");
		return transition;
	}

}
